﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Sudum
{
    public enum FlowAction
    {
        FlowTo_Continue,	// Keep updating the current state
        FlowTo_IntroScene,  // Transition to the Intro scene state           
        FlowTo_Play,		// Transition to the game play state
        FlowTo_Exit,		// Transition to the exit state
        FlowTo_PrincipalMenu,
        FlowTo_Story,
        FlowTo_ChooseLevel,
        FlowTo_EditLevel,
        FlowTo_DevelopmentTeam,
        FlowTo_Help
    }

    interface IGameState
    {
        FlowAction Update();
        void Render();
    }

    class StateFlow
    {
        IGameState currentState;	

        public StateFlow()
        {
        }

        public bool Update()
        {
            FlowAction nextFlowAction = FlowAction.FlowTo_IntroScene;
            if (currentState != null)
	        {
                nextFlowAction = currentState.Update();
                if (nextFlowAction == FlowAction.FlowTo_Continue)
			        return true;
                if (nextFlowAction == FlowAction.FlowTo_Exit)
                    return false;
	        }

	        currentState = null;

	        // Create the next state
            switch (nextFlowAction)
            {
                case FlowAction.FlowTo_IntroScene:
                    currentState = new GameState_VideoPlayback("Video\\intro", FlowAction.FlowTo_PrincipalMenu);
                    break;

                case FlowAction.FlowTo_Play:
                    {
                        currentState = new GameState_Play();
                        GameState_Play gameplayState =
                            (GameState_Play)currentState;
                        if (!gameplayState.SetLevel())
                            currentState = null;
                    }
                    break;

                case FlowAction.FlowTo_PrincipalMenu:
                    currentState = new GameState_PrincipalGameMenu();
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false, "FlowAction not handled");
                    break;
            }

	        if (currentState != null)
                currentState.Update();
            return true;
        }

        public void Render()
        {
            if (currentState != null)
                currentState.Render();
        }
    } // end "StateFlow" class
}